var Card = new Class({
	Extends: Thing,
	
	initialize: function(number, top, left) {
		this.parent(top, left);
		this.load(number);
	},
	
	load: function(number) {
		this.loadElement(number, (function(element) {
			element.getElements('a').each(function(link) {
				link.addClass('nolink');
				link.addEvent('click', function(e) {
					e.preventDefault();
				});
			});
			element.addEvent('mouseenter', (function() {
				var oldzoomed = document.id('cardzoom').getFirst();
				if(oldzoomed) {
					oldzoomed.dispose();
				}
				if(this.zoomedcard) {
					document.id('cardzoom').grab(this.zoomedcard);
				}
			}).bind(this));
			element.addEvent('mouseleave', function() {
				var oldzoomed = document.id('cardzoom').getFirst();
				if(oldzoomed) {
					oldzoomed.dispose();
				}
			});
			element.set('data-number', number);
			this.include(element, 0.4);
		}).bind(this));
		this.loadElement(number, (function(element) {
			this.zoomedcard = element;
		}).bind(this));
	},
	loadElement: function(number, callback) {
		new Request.JSONP({
			url: 'http://kamelopedia.mormo.org/api.php',
			data: {
				action: 'parse',
				text: '{{Karte|' + number + '}}',
				prop: 'text',
				format: 'json'
			},
			onComplete: function(data) {
				var element = new Element('div', {
					html: data.parse.text['*'].replace(/src="\//g, 'src="http://kamelopedia.mormo.org/').replace(/href="\//g, 'href="http://kamelopedia.mormo.org/')
				});
				(Function.from(callback))(element);
			}
		}).send();
	}
});